/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUIs;

import Core.ConnectionToDatabase;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author jc156563
 */
public class CreateInventoryItemUI extends Frame implements ActionListener
{

    protected JTextField nameText, quantityText;
    protected JFrame frame;

    public void show()
    {
        frame = new JFrame("Create Item");
        JPanel panel = new JPanel();
        JLabel nameLabel = new JLabel("Enter Item Name");
        JLabel quantityLabel = new JLabel("Enter Item Quantity");
        JButton enterDetails = new JButton("Add Item");
        JButton back = new JButton("Back");
        
        nameText = new JTextField(20);
        quantityText = new JTextField(20);
        nameText.setText("");
        quantityText.setText("");


        
        panel.add(nameLabel);
        panel.add(nameText);
        panel.add(quantityLabel);
        panel.add(quantityText);
        panel.add(enterDetails);
        panel.add(back);
        
        enterDetails.addActionListener(this);
        enterDetails.setActionCommand("create");
        back.addActionListener(this);
        back.setActionCommand("back");

        frame.setSize(256, 256);
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public void actionPerformed(ActionEvent e)
    {
        String action;
        action = e.getActionCommand();

        if (action.equals("create"))
        {
            ConnectionToDatabase con = new ConnectionToDatabase();
            String itemName = "";

            String itemQty = "";
            itemName = nameText.getText();
            itemQty = quantityText.getText();
            if(con.addItem(itemName, itemQty))
            {
                JOptionPane.showMessageDialog(frame, "Item Added Successfully");
            }
            else
            {
                JOptionPane.showMessageDialog(frame, "Item Was Not Added Successfully");
            }
            frame.setVisible( false );
            frame.dispose();
            CreateInventoryItemUI newWindow = new CreateInventoryItemUI();
            newWindow.show();
        }
        else if (action.equals("back"))
        {
            MainUI main = new MainUI();
            main.show();
            frame.setVisible( false );
            frame.dispose();
        }
    }

    public static void CreateInventoryItemUI()
    {

    }
}
